<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组扁平化</title>
</head>

<body>
  <script>
    //1.
    // let arr = [1, [2, [3, 4, 5]]];
    // arr = arr.toString().split(',')

    // console.log(arr.map(Number))
    //2.
    let arr = [{ id: 1, children: [{ id: 11, children: [{ id: 111, }] }, { id: 12, }] },
    { id: 2, children: [{ id: 21, children: [] }] }]
    let sum = []
    //  forEach数组每个元素都执行一次回调函数
    let num = arr.forEach((a) => {
      //用于确定传递的值是否是一个数组，是返回truc，不是返回falsc。
      if (Array.isArray(a)) {
        arr(a)
      }
      else {
        sum.push(a)
      }
    })
    console.log(sum)
    console.log(arr)
  </script>
</body>

</html>